import $C from '@/common/config.js';
export default {
	/**
	 * 设置用户登录信息
	 * @param {Object} loginInfo 用户登录信息
	 * @param {Object} callback
	 */
	saveLoginInfo(loginInfo) {
		try {
			//console.log($C)
		    uni.setStorageSync($C.Key.login_info, JSON.stringify(loginInfo));
			return true
		} catch (e) {
		    // error
			//console.log(e)
			return false
		}
	},
	/**
	 * 获取用户登录信息
	 */
	getLoginInfo() {
		try {
		    const value = uni.getStorageSync($C.Key.login_info);
		    if (value) {
		        return JSON.parse(value)
		    }
		} catch (e) {
		    // error
		}
		return null
	},
	/**
	 * 获取接口请求秘钥
	 */
	getBladeAuth() {
		let loginInfo = this.getLoginInfo();
		if(loginInfo) {
			// return loginInfo.tokenType + ' ' + loginInfo.accessToken
			return loginInfo.token
		}
		return ''
	},
	/**
	 * 获取refreshToken
	 */
	getRefreshToken() {
		let loginInfo = this.getLoginInfo();
		if(loginInfo) {
			return loginInfo.refreshToken
		}
		return ''
	},
	/**
	 * 管理员id
	 */
	getUserId() {
		let loginInfo = this.getLoginInfo();
		if(loginInfo) {
			return loginInfo.admin_id
		}
		return ''
	},
	/**
	 * 是否分配医院
	 */
	getHospitalId() {
		let loginInfo = this.getLoginInfo();
		if(loginInfo) {
			return loginInfo.hospital_id
		}
		return ''
	},
	getRoleName() {
		try {
		    const value = uni.getStorageSync($C.Key.login_role);
		    return value
		} catch (e) {
		    // error
		}
		return ''
	},
	/**
	 * 租户ID
	 */
	getTenantId() {
		let loginInfo = this.getLoginInfo();
		if(loginInfo) {
			return loginInfo.tenantId
		}
		return ''
	},
	clearLoginInfo() {
		try {
		    uni.removeStorageSync($C.Key.login_info);
		} catch (e) {
		    // error
		}
	},
	//保存登录类型
	saveLoginUserType(type) {
		try {
			uni.setStorageSync($C.Key.login_user_type,type)  //1-账号登录  2-关联账号登录
			return true
		} catch (e) {
		    // error
			//console.log(e)
			return false
		}
	},
	/**
	 * 获取用户登录类型
	 */
	getLoginUserType() {
		try {
		    const value = uni.getStorageSync($C.Key.login_user_type);
		    return value ? value : 1;
		} catch (e) {
		    // error
		}
		return null
	},
	//保存openid
	saveUserOpenid(openid) {
		try {
		    uni.setStorageSync($C.Key.user_openid, openid);
			return true
		} catch (e) {
		    // error
			//console.log(e)
			return false
		}
	},
	//获取openid
	getUserOpenid() {
		try {
			//console.log($C)
		    const value = uni.getStorageSync($C.Key.user_openid);
			return value ? value : '';
		} catch (e) {
		    // error
			//console.log(e)
			return null
		}
	},
	
}